package BanyuanClub.Work.Story.Five;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 封装一个Hashmap
 */
public class Datebase {
    private Map<String,Student> map = new HashMap<>();

    @Override
    public String toString() {
        return "Datebase{" +
                "map=" + map +
                '}';
    }

    public Datebase(){
        this.map.put("111",new Student("111","aaa",20));
        this.map.put("222",new Student("222","bbb",25));
        this.map.put("333",new Student("333","ccc",30));
    }

    public Collection<Student> selectAll(){
        return map.values();
    }

    public Student selectByid(String id){
        return map.get(id);
    }

    public Student insert(Student stu){
        return map.put(stu.getId(),stu);
    }

    public Student delete(String id){
        return map.remove(id);
    }

    public void update(Student newstu){
        Student stu = map.get(newstu.getId());
        stu.setName(newstu.getName());
        stu.setAge(newstu.getAge());

    }
}
